package com.trkj.dao;

import com.trkj.entity.Dept;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.sql.DataSource;
import java.sql.ResultSet;
import java.sql.SQLException;
@Repository
public class DeptDao extends JdbcDaoSupport {

   public Dept findDeptById(int deptno){
       String sql="select * from dept where deptno=?";

       Dept dept=this.getJdbcTemplate().queryForObject(sql, new RowMapper<Dept>() {
           @Override
           public Dept mapRow(ResultSet rs, int rowNum) throws SQLException {
               Dept dept1=new Dept();
               dept1.setDeptno(rs.getInt(1));
               dept1.setDname(rs.getString(2));
               return dept1;
           }
       },deptno);
       return dept;
   }

//   public int addDept(Dept dept){
//       String sql="insert into dept(deptno,dname,loc) values(?,?,?)";
//       int count=this.getJdbcTemplate().update(sql,dept.getDeptno(),dept.getDname(),dept.getLoc());
//       return count;
//   }
    public DeptDao(DataSource druidDataSource){
        setDataSource(druidDataSource);
    }

}

